package com.ssm.server.feign.registrar;

import com.ssm.server.feign.annotaion.EnableMyFeignClients;
import com.ssm.server.feign.annotaion.MyFeignClient;
import com.ssm.server.feign.scanner.MyFeignScanner;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

public class MyFeignRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata am, BeanDefinitionRegistry re){
        AnnotationAttributes ana = AnnotationAttributes.fromMap(
                am.getAnnotationAttributes(EnableMyFeignClients.class.getName()));
        MyFeignScanner sc  = new MyFeignScanner(re);
        sc.addIncludeFilter((mr,mf)->//必须是接口 不可以注解 必须被我自定义注解比标记
             mr.getAnnotationMetadata().isIndependent() && mr.getAnnotationMetadata().isInterface() &&
                    !mr.getAnnotationMetadata().isAnnotation() &&
                    mr.getAnnotationMetadata().hasAnnotation(MyFeignClient.class.getName())
        );
        sc.doScan(ana.getStringArray("backPackages"));
    }
}
